
CLEANFILES = cpp/quantlib_wrap.* csharp/*.cs *.so *.dll \
             examples/*.so examples/*.dll examples/*.exe

BUILT_SOURCES = cpp/quantlib_wrap.cpp cpp/quantlib_wrap.h

if HAVE_MCS
if BUILD_MCS

all-local: libNQuantLibc.so NQuantLib.dll

libNQuantLibc.so: cpp/quantlib_wrap.o
	$(CXX) -shared cpp/quantlib_wrap.o -o libNQuantLibc.so `quantlib-config --libs`

cpp/quantlib_wrap.o: $(BUILT_SOURCES)
	$(CXX) -c -fpic $(CXXFLAGS) cpp/quantlib_wrap.cpp -o cpp/quantlib_wrap.o `quantlib-config --cflags`

NQuantLib.dll: $(BUILT_SOURCES)
	$(MCS) -nologo -target:library -out:NQuantLib.dll csharp/*.cs

check-local: examples/BermudanSwaption.exe \
             examples/EquityOption.exe \
             examples/libNQuantLibc.so examples/NQuantLib.dll
	$(MONO) ./examples/BermudanSwaption.exe
	$(MONO) ./examples/EquityOption.exe

examples/%.exe: examples/%.cs
	$(MCS) -nologo -target:exe -out:$@ -reference:NQuantLib.dll $<

examples/libNQuantLibc.so: libNQuantLibc.so
	cd examples && ln -sf ../libNQuantLibc.so

examples/NQuantLib.dll: NQuantLib.dll
	cd examples && ln -sf ../NQuantLib.dll

endif
endif

$(BUILT_SOURCES): ../SWIG/*.i
	$(SWIG) -csharp -c++ -outdir csharp \
            -namespace QuantLib -o cpp/quantlib_wrap.cpp ../SWIG/quantlib.i

dist-hook: $(BUILT_SOURCES)
	mkdir -p $(distdir)/cpp
	cp ./cpp/*.vcxproj $(distdir)/cpp
	cp ./cpp/quantlib_wrap.cpp $(distdir)/cpp
	cp ./cpp/quantlib_wrap.h $(distdir)/cpp
	cp ./cpp/QuantlibWrapper.h ./cpp/QuantlibWrapper.cpp $(distdir)/cpp
	cp ./cpp/stdafx.h $(distdir)/cpp
	mkdir -p $(distdir)/csharp
	cp ./csharp/*.csproj $(distdir)/csharp
	cp ./csharp/*.cs $(distdir)/csharp
	mkdir -p $(distdir)/examples
	cp ./examples/*.csproj $(distdir)/examples
	cp ./examples/*.cs $(distdir)/examples

EXTRA_DIST = \
    QuantLib.sln \
    QuantLib.props \
    swig.cmd \
    README.txt

